package com.word.app.service.impl;

import com.word.app.pojo.Question;
import com.word.app.mapper.QuestionMapper;
import com.word.app.service.IQuestionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.*;

import org.springframework.stereotype.Service;

/**
 * @author nano
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements IQuestionService {
    public IPage<Question> queryRandom(Page<Question>page, Question entity){
        return this.baseMapper.queryRandom(page, entity);
    }
    public HashMap<Integer, Integer> getCount(Integer subjectId){
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        Question question = new Question();
        QueryWrapper<Question> wrapper = new QueryWrapper<Question>();
        question.setSubject(subjectId);
        for(int type=0; type<4; type++){
            question.setType(type);
            wrapper.setEntity(question);
            
            map.put(type, this.baseMapper.selectCount(wrapper));
        }
        return map;
    }

}
